import store from "../store/index.js";
import jwt_decode from "jwt-decode";
import { Login } from '@/api/index.js';
export const PasswordFreeLogin = async () => {
	console.log('免密登录')
	uni.showLoading({
	    title: '免密登录中'
	});
	const { authCode } = await dd.getAuthCode();
	// console.log(authCode,'authCode')
	const { data, success, msg } = await Login.userLogin({ nickname: authCode, platform: 'mini' });
	if (success) {
		uni.setStorageSync('token', 'Bearer ' + data.token);
		const tokenInfo = jwt_decode(data.token);
		store.commit('changeUserInfo', tokenInfo)
		uni.setStorageSync('userInfo', JSON.stringify(tokenInfo));
		uni.hideLoading();
	} else {
		uni.hideLoading()
		uni.showToast({
			title: msg,
			icon: 'none',
			mask: true,
			duration: 1500,
		})
	}
}